package com.jrfid.smartcabinet.demo.ui.cabinet_config.adapter

import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.BaseDraggableModule
import com.chad.library.adapter.base.module.DraggableModule
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.jrfid.smartcabinet.demo.R
import com.jrfid.smartcabinet.demo.databinding.ItemCabinetConfigBinding
import com.jrfid.smartcabinet.demo.model.CabinetConfigInfoModel

class CabinetConfigAdapter : BaseQuickAdapter<CabinetConfigInfoModel, BaseDataBindingHolder<ItemCabinetConfigBinding>>(R.layout.item_cabinet_config), DraggableModule {

    init {
        addChildClickViewIds(R.id.btn_test_rfid)
        addChildClickViewIds(R.id.btn_test_ic)
        addChildClickViewIds(R.id.btn_test_finger)
    }

    override fun convert(holder: BaseDataBindingHolder<ItemCabinetConfigBinding>, item: CabinetConfigInfoModel) {
        holder.dataBinding?.let {
            it.position = holder.adapterPosition
            it.viewModel = item
            it.executePendingBindings()
        }
    }

    override fun addDraggableModule(baseQuickAdapter: BaseQuickAdapter<*, *>): BaseDraggableModule {
        return SwipeDeleteModule(baseQuickAdapter)
    }
}